'''

	Inspector and doc generator



'''


#print "INSPECT"
#import my_token as token
#print dir(token)

#print "MY TEST"
#import my_test
#print "dir",dir(my_test)

#print "MY my_sre_constants"
import my_sre_constants
#print "dir",dir(my_sre_constants)
my_sre_constants.__all__ = dir(my_sre_constants)
#print "all", my_sre_constants.__all__
#print "#", my_sre_constants.SRE_FLAG_IGNORECASE
#print 

#print "my_sre_constants"
#import my_sre_constants
#print "dir", dir(my_sre_constants)
#my_sre_constants.__all__ = dir(my_sre_constants)
#print "all", my_sre_constants.__all__
#print "#", my_sre_constants.SRE_FLAG_IGNORECASE
#print 

#print "my_sre_compile"
import my_sre_compile
#print "dir", dir(my_sre_compile)
my_sre_compile.__all__ = dir(my_sre_compile)
#print "all", my_sre_compile.__all__
#print "#", my_sre_compile.SRE_FLAG_IGNORECASE
#print 

import imp
import my_inspect as inspect
import my_os as os
import my_re as re
import sys
import my_types as types


from my_pydoc import *

_DONE = []

def GenDoc( name, path ):
    global _DONE
    _DONE = []
    _GenModuleDoc( name, path )
    print "Doc updated:"
    for n in _DONE:
        print "   ",n
        
def _GenModuleDoc( name, path ):
    global _DONE
    object = locate(name)
    page = html.page(
        describe(object),
        html.document(object, name)
    )
    filename = path+"/"+name.split('.')[-1]+".html"
    file = open(filename, 'w')
    file.write(page)
    file.close()
    print 'wrote doc to', filename
    _DONE.append( name )
    
    subs = inspect.getmembers( object, inspect.ismodule )
    for subName, obj in subs:
        if subName in _DONE:
            print "------------- Skipping", name+'.'+subName
            continue
        _GenModuleDoc( name+'.'+subName, path )
    
